import { ArticeApi } from '@/view/article-manage/article-list/api'
import { ref } from 'vue'
import { useRouter } from 'vue-router'

export class ArchiveClass {
	archiveInfo = ref()
	router = useRouter()
	list = ref([])
	constructor() {
		this.getArchive()
	}

	/**
	 *  获取归档文章
	 */
	public getArchive() {
		ArticeApi.getGroupedArticle().subscribe(res => {
			this.archiveInfo.value = res
			Object.keys(this.archiveInfo.value)?.map(item => {
				this.list.value.push({
					date: item,
					result: this.archiveInfo.value[item]
				})
			})
		})
	}

	/**
	 * 查看下详情
	 */
	public todetails(id: number) {
		this.router.push({ path: '/article', query: { id: id } })
	}
}
